<?php
abstract class AbstractGun{
    //枪用来干什么的？杀敌！
    public abstract function shoot();
}
    
class Handgun extends AbstractGun{
    //手枪的特点是携带方便，射程短
    public function shoot(){
        println ("手枪射击……");
    }
} 
    
class Rifle extends  AbstractGun{
    //步枪的特点是射程远，威力大
    public function shoot(){
        println ("步枪射击……");
    }
} 

class MachineGun extends AbstractGun{
    public function shoot(){
        println ("机枪扫射……");
    }
}
       
class AUG extends Rifle {
    //狙击枪都携带一个精准的望远镜
    public function zoomOut(){
        println("通过望远镜察看敌人...");
    }
    public function shoot(){
        println("AUG射击...");
    }
}

class Soldier{
    //定义士兵的枪支
    protected $gun;
    //给士兵一支枪
    public function setGun(AbstractGun $_gun){
        $this->gun=$_gun;
    } 
    
    public function killEnemy(){
        println ("士兵开始杀敌人……");
        $this->gun->shoot();
    }
}

class Snipper extends Soldier {
    public function killEnemy(){
        println ("狙击开始……");
        //首先看看敌人的情况，别杀死敌人，自己也被人干掉
        $this->gun->zoomOut();
        //开始射击
        $this->gun->shoot();
    }
}

//产生三毛这个士兵
$sanMao=new Soldier();
//给三毛一支枪
$sanMao->setGun(new Rifle());
$sanMao->killEnemy();

//产生三毛这个狙击手
$zuiMa = new Snipper();
$zuiMa->setGun(new AUG());
$zuiMa->killEnemy();

function println ($str){
    echo $str."\n";    
}


